package vn.bang.xiangqi.components;

import java.util.Collection;

import vn.bang.xiangqi.infrastructure.Position;
import vn.bang.xiangqi.infrastructure.Vector;
import vn.bang.xiangqi.utility.BoardUtil;

public class Chariot extends AbstractBaseNode {
	public Chariot() {
		super();
	}

	public Chariot(Position originalPosition) {
		super(originalPosition);
	}

	@Override
	protected boolean notPrevented(Vector vector, Collection<INode> ours,
			Collection<INode> enemies) {
		return !hasNodeBetween(vector, ours, enemies);
	}

	@Override
	protected Vector retrieveVectorMovingTo(Position destinationPosition) {
		if (null == destinationPosition
				|| !BoardUtil.IsInBoard(destinationPosition)) {
			return null;
		}

		Vector vector = null;

		if (position.getColumnIndex() == destinationPosition.getColumnIndex()) {
			vector = new Vector(0, destinationPosition.getRowIndex()
					- position.getRowIndex());
		}

		if (position.getRowIndex() == destinationPosition.getRowIndex()) {
			vector = new Vector(destinationPosition.getColumnIndex()
					- position.getColumnIndex(), 0);
		}

		return vector;
	}

}